#ifndef _OPENGLAPPFRAMEWORK_MESH_MESH_H_
#define _OPENGLAPPFRAMEWORK_MESH_MESH_H_

#include "OpenglAppFramework/inc/OpenglEnv.h"
#include "OpenglAppFramework/inc/PlugIn/PlugIn.h"
#include "ObjLoader/inc/ObjLoader.h"
#include <cstdint>
#include <string>

class Mesh : public PlugIn {
public:
    Mesh(const std::string& name);
    ~Mesh();

    int init() override;
    void destroy() override;
    int setConfigData(const nlohmann::json& data) override;
    
    uint32_t getVAOId() const;
    uint32_t getPrimitVertexCount() const;
    bool hasIndexBuffer() const;
    // 取了就必须用
    uint32_t getNextAttrIndex();
    
    // void render();
    std::string info() const;
private:
    int loadData();
    
    /*          子类需要在set()方法正确设置下成员变量                   */
    /*      没有vtx_idx的情况下，m_primit_vtx_idxs必须设置为nullptr    */
    /**/    uint32_t m_primit_cnt;      // 图元个数
    /**/    uint32_t m_primit_vtx_cnt;  // 图元个数 x 每个图元的顶点数
    /**/    uint32_t m_vtx_cnt;         // 总顶点数（不重复）
    /**/    
    /**/    float* m_vtx_cords, *m_vtx_norm, *m_vtx_tex_cords;
    /**/    uint32_t m_vtx_cords_offset, m_vtx_norm_offset, m_vtx_tex_cords_offset;
    /**/    uint32_t m_vtx_cords_size, m_vtx_norm_size, m_vtx_tex_cords_size;
    /**/    uint32_t* m_primit_vtx_idxs;
    /**/    uint32_t m_primit_vtx_idxs_size;

    uint32_t m_vbo_size;
    uint32_t m_vao_id, m_vbo_id, m_ebo_id;
    uint32_t m_vtx_attr_idx;
    
    std::string m_obj_dir;
    std::string m_obj_file_name;
    ObjLoader m_obj_loader;
};

#endif//#define _OPENGLAPPFRAMEWORK_MESH_MESH_H_

